import { mergeConfig, defineConfig } from 'vite';
import eslint from 'vite-plugin-eslint';
import baseConfig from './vite.config.base';
import viteEnv from './vite.env';
import { baseUrlConfig, developBaseUrl } from '../src/api/http/httpConfig';

export default defineConfig(({ mode }) => {
  return mergeConfig(
    {
      mode: 'development',
      server: {
        open: true,
        fs: {
          strict: true,
        },
        proxy: viteEnv[mode].proxy
          ? {
              [developBaseUrl]: {
                target: baseUrlConfig[mode],
                changeOrigin: true,
                rewrite: (path) => {
                  return path.replace(developBaseUrl, '');
                },
              },
            }
          : {},
      },
      plugins: [
        eslint({
          cache: false,
          include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
          exclude: ['node_modules'],
        }),
      ],
      define: {
        'process.env': {
          ...viteEnv[mode],
          runMode: 'dev',
        },
      },
    },
    baseConfig
  );
});
